home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 5 / Apprentice-Release5.iso / Source Code / Libraries / ClutFade 1.3.2 / Pascal / TestfadeC.p < prev   
Text File  |  1996-05-15  |  5KB  |  198 lines

  1. program TestFade;
  2.  
  3. {/********************************************************************************    }
  4.  
  5. {     PROJECT:    clut_fade.π                                                            }
  6.  
  7. {     FILE:        shell.c                                                                }
  8.  
  9. {     PURPOSE:    'clut' fading functions}
  10. {     }
  11. {     STATUS:        Public Domain Demo.                                                    }
  12.  
  13. {********************************************************************************/    }
  14.  
  15.  
  16.     uses
  17.         Fade;
  18.  
  19.  
  20.  
  21. {********************************************************************************/    }
  22.     procedure init_toolbox;
  23.     begin
  24.         MaxApplZone;
  25.         MoreMasters;
  26.         InitGraf(@thePort);
  27.         InitFonts;
  28.         InitWindows;
  29.         InitMenus;
  30.         TEInit;
  31.         InitDialogs(nil);
  32.         InitCursor;
  33.         FlushEvents(everyEvent, 0);
  34.     end;
  35.  
  36. {********************************************************************************/    }
  37.     procedure test_window;
  38.  
  39.         var
  40.             d: DialogPtr;
  41.             g: GrafPtr;
  42.             hit: integer;
  43.             hGD: GDHandle;
  44.             hCTab: CTabHandle;
  45.             ticks: longint;
  46.             fadeSpeed: integer;
  47.             iHandle: Handle;
  48.             iType: integer;
  49.             iRect: Rect;
  50.             tHandle: Handle;
  51.             th2: CTabHandle;
  52.             origColors: CTabHandle;
  53.             mainDevice: GDHandle;
  54.             aColor: RGBColor;
  55.             newColors: CTabHandle;
  56.             x: integer;
  57.  
  58.     begin
  59.         d := GetNewDialog(128, nil, pointer(-1));
  60.         if d <> nil then
  61.             begin
  62.                 GetPort(g);
  63.                 SetPort(d);
  64.                 ShowWindow(d);
  65.  
  66.                 repeat
  67.                     ModalDialog(nil, hit);
  68.                     GetDItem(d, 10, iType, iHandle, iRect);
  69.                     fadeSpeed := GetCtlValue(ControlHandle(iHandle));
  70.                     case hit of
  71.  
  72.                 {// fade all monitors to black}
  73.                         2: 
  74.                             begin
  75.                         {// fade out}
  76.                                 fade_to_black(fadeSpeed, fadeAll, true);
  77.                         {// wait a few seconds}
  78.                                 Delay(120, ticks);
  79.                         {// fade in}
  80.                                 fade_to_black(fadeSpeed, fadeAll, false);
  81.                             end;
  82.  
  83.                 {// fade main monitor to black}
  84.                         3: 
  85.                             begin
  86.                         {// fade out}
  87.                                 fade_to_black(fadeSpeed, fadeMainOnly, true);
  88.                         {// wait a few seconds}
  89.                                 Delay(120, ticks);
  90.                         {// fade in}
  91.                                 fade_to_black(fadeSpeed, fadeMainOnly, false);
  92.                             end;
  93.  
  94.                 {// fade all monitors except main monitor to black}
  95.                         4: 
  96.                             begin
  97.                         {// fade out}
  98.                                 fade_to_black(fadeSpeed, fadeAllButMain, true);
  99.                         {// wait a few seconds}
  100.                                 Delay(120, ticks);
  101.                         {// fade in}
  102.                                 fade_to_black(fadeSpeed, fadeAllButMain, false);
  103.                             end;
  104.  
  105.                 {// fade main monitor to red}
  106.                         5: 
  107.                             begin
  108.  
  109.                                 mainDevice := GetMainDevice;
  110.                         {// make a copy of the color table so we can restore it later}
  111.                                 copy_gdevice_clut(mainDevice, origColors);
  112.  
  113.                         {// fade to a color}
  114.                                 aColor.red := 65535;
  115.                                 aColor.green := 0;
  116.                                 aColor.blue := 0;
  117.                                 fade_to_color(fadeSpeed, aColor, mainDevice);
  118.  
  119.                         {// wait a few seconds}
  120.                                 Delay(120, ticks);
  121.  
  122.                         {// fade back to original color table}
  123.                                 fade_to_clut(fadeSpeed, origColors, mainDevice);
  124.  
  125.                         {// dispose the copy we made}
  126.                                 DisposeHandle(Handle(origColors));
  127.                             end;
  128.  
  129.                         {// fade main monitor through rainbow}
  130.                         6: 
  131.                             begin
  132.                                 mainDevice := GetMainDevice;
  133.  
  134.                         {// make a copy of the color table so we can restore it later}
  135.                                 copy_gdevice_clut(mainDevice, origColors);
  136.  
  137.                                 for x := 128 to 134 do {for (x = 128; x < 135; x++)}
  138.                                     begin
  139.                             {// get a custom color table (red or blue)}
  140.                                         newColors := GetCTable(x);
  141.                             {// limit it to current depth}
  142.                                         newColors^^.ctSize := origColors^^.ctSize;
  143.                                         SetHandleSize(Handle(newColors), GetHandleSize(Handle(origColors));
  144.                             {// fade to the custow color table}
  145.                                         fade_to_clut(40, newColors, mainDevice);
  146.                                         ReleaseResource(Handle(newColors));
  147.                                     end;
  148.  
  149.                         {// fade back to original color table}
  150.                                 fade_to_clut(40, origColors, mainDevice);
  151.                         {// dispose the copy we made}
  152.                                 DisposeHandle(Handle(origColors));
  153.                             end;
  154.  
  155.                         {// fade to inverted clut}
  156.                         7: 
  157.                             begin
  158.  
  159.                                 mainDevice := GetMainDevice;
  160.  
  161.                         {// make a copy of the color table so we can restore it later}
  162.                                 copy_gdevice_clut(mainDevice, origColors);
  163.                         {// make a copy of the color table so we manipulate it}
  164.                                 copy_gdevice_clut(mainDevice, newColors);
  165.                         {// reverse order of colors for a fun effect}
  166.  
  167.                                 for x := 0 to (newColors^^.ctSize + 1) div 2 do {for (x = 0; x < (((**newColors).ctSize+1)/2); x++)}
  168.                                     begin
  169.                                         aColor := newColors^^.ctTable[x].rgb;
  170.                                         newColors^^.ctTable[x].rgb := newColors^^.ctTable[newColors^^.ctSize - x].rgb;
  171.                                         newColors^^.ctTable[newColors^^.ctSize - x].rgb := aColor;
  172.                                     end;
  173.                         { change the ctSeed so we know it is different than original }
  174.                                 newColors^^.ctSeed := GetCTSeed;
  175.  
  176.                         {// fade to it}
  177.                                 fade_to_clut(fadeSpeed, newColors, mainDevice);
  178.                         {// wait a few seconds}
  179.                                 Delay(120, ticks);
  180.                         {// fade back to original color table}
  181.                                 fade_to_clut(fadeSpeed, origColors, mainDevice);
  182.                         {// dispose the copy we made}
  183.                                 DisposeHandle(Handle(origColors));
  184.                             end;
  185.                     end;
  186.                 until (hit = 1);
  187.  
  188.                 SetPort(g);
  189.                 DisposDialog(d);
  190.             end;
  191.     end;
  192.  
  193.  
  194. {/*********************************** main ***************************************/}
  195. begin
  196.     init_toolbox;
  197.     test_window;
  198. end.